﻿//#define _CRT_SECURE_NO_WARNINGS  1
////一定要动手，例子不管多么简单，建议至少自己手敲一遍看看是否理解了里头的细枝末节。
////一定要学会思考，思考为什么要这样，而不是那样。还要举一反三地思考
//#include<string>
//#include<iostream>
//using namespace std;
////普通方式实现
////class  Calculator {
////public:
////	int _num1;
////	int _num2;
////public:
////	int getstr(string str)
////	{
////		if (str == "+")
////		{
////			return _num1 + _num2;
////		}
////
////		if (str == "-")
////		{
////			return _num1 - _num2;
////		}
////		if (str == "*")
////		{
////			return _num1 * _num2;
////		}
////	}
////};
//// 如果想要添加新功能，需要修改源码
//// 在真实开发中，提倡开闭原则
//// 开闭原则：对扩展进行开放，对修改进行关闭
////void test()
////{
////	Calculator c;
////	c._num1 = 10;
////	c._num2 = 10;
////	cout << "_num1+_num1 = " << c.getstr("+") << endl;
////	cout << "_num1-_num1 = " << c.getstr("-") << endl;
////	cout << "_num1*_num1 = " << c.getstr("*") << endl;
////
////}
//
//
//
////多态实现计算器
////多态实现的好处
////1.组织结构清晰
////2.可读性强
////3.对于前期和后期扩展以及维护性高
//class Calculator2 {
//public:
//	int _num1;
//	int _num2;
//public:
//	virtual int getstr()
//	{
//		return _num1 + _num2;
//	}
//};
////加法计算器类
//class add :public Calculator2 {
//public:
//	virtual int getstr()
//	{
//		return _num1 + _num2;
//	}
//};
////减法计算器类
//class subtraction :public Calculator2 {
//public:
//	virtual int getstr()
//	{
//		return _num1 - _num2;
//	}
//};
////乘法计算器类
//class multiplication :public Calculator2 {
//public:
//	virtual int getstr()
//	{
//		return (_num1*_num2);
//	}
//};
//void test()
//{
//	//多态的使用条件
//	//父类的指针或引用指向子类对象
//	//动态
//	Calculator2* abc = new multiplication;
//	abc->_num1 = 10;
//	abc->_num2 = 29;
//	cout << abc->_num1 << " * " << abc->_num2 << " = " << abc->getstr() << endl;
//	delete abc;
//	abc = new add;
//	abc->_num1 = 10;
//	abc->_num2 = 29;
//	cout << abc->_num1 << " + " << abc->_num2 << " = " << abc->getstr() << endl;
//
//
//}
//int main()
//{
//	test();
//	return 0;
//}